%{ open Ast %}

%token NOT
%token PLUS MINUS TIMES DIVIDE LT GT EQ NEQ AND OR
%token ASSIGN COMMA SEMI LPAREN RPAREN LBRACE RBRACE LBRACK RBRACK
%token IF ELSE FOR WHILE UNTIL
%token <int> NUM
%token <string> ID
%token <string> DATATYPE
%token EOF

/* lowest precedence */
%right ASSIGN
%left AND OR EQ NEQ
%left LT GT
%left PLUS MINUS
%left TIMES DIVIDE
%right NOT
/* highest precedence */

%start program
%type < Ast.program> program

%%

/* what is a program?? */
program:
		    { [], [] }
| program vdecl	    { (%2 :: fst $1), snd $1 }
| program fdecl	    { fst $1, ($2 :: snd $1) }


expr:
  expr PLUS   expr  { Binop($1, Add, $3) }
| expr MINUS  expr  { Binop($1, Sub, $3) }
| expr TIMES  expr  { Binop($1, Mul, $3) }
| expr DIVIDE expr  { Binop($1, Div, $3) }
| LITERAL	    { Lit($1) }
